import 'package:flutter/cupertino.dart';
import 'package:hitutor/UI/AudioPlayerPage.dart';
import 'package:hitutor/UI/Home/Home.dart';
import 'package:hitutor/Util/DateUtil.dart';
import 'package:hitutor/Util/Global.dart';
import 'package:hitutor/Util/MyColor.dart';
import 'package:hitutor/Util/PageUtil.dart';
import 'package:hitutor/Widget/MyBgPage.dart';
import 'package:hitutor/Widget/MyButton.dart';
import 'package:hitutor/Widget/MyImage.dart';
import 'package:hitutor/Widget/MyPage.dart';

import '../ChooseMaterial.dart';

class PreviewClass extends StatefulWidget {
  dynamic data;

  PreviewClass(this.data);

  @override
  State<StatefulWidget> createState() {
    return _PreviewClass();
  }
}

class _PreviewClass extends State<PreviewClass> {
  @override
  Widget build(BuildContext context) {
    String beginTime = getStrTime(getTimeByUtc(widget.data["beginTime"]), DateUtil.YMDHM);
    String endTime = getStrTime(getTimeByUtc(widget.data["endTime"]), DateUtil.HM);

    String className = widget.data["lessonName"].toString();
    // if (className.length > 10) {
    //   className = className.substring(0, 10) + "...";
    // }

    return MyBgPage(
        "",
        Column(
          children: [
            Container(height: 24),
            Text("$beginTime - $endTime", style: TextStyle(fontSize: 14, color: MyColor.Green, fontWeight: FontWeight.bold)),
            Text("$className",
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 14, height: 2, color: Color(0xffff8484), fontWeight: FontWeight.bold)),
            Text("授課老師：${widget.data["teacherName"]}", style: TextStyle(fontSize: 13, height: 2, color: MyColor.C58)),
            Container(
                decoration: Global.getWhiteBg_shadow(8, MyColor.DD),
                padding: EdgeInsets.all(12),
                margin: EdgeInsets.all(12),
                child: Column(children: [
                  Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                    LocalImage("book.png", height: 24, width: 32),
                    Text("今日課程", style: TextStyle(fontSize: 14, color: MyColor.Orange, fontWeight: FontWeight.bold))
                  ]),
                  Container(height: 0.5, color: MyColor.Orange, margin: EdgeInsets.only(top: 6, bottom: 16)),
                  Row(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [
                    Button("${widget.data["plateformShortName"]}",
                        height: 22, width: 22, bgColor: MyColor.C5, radius: 20, fontSize: 11, margin: EdgeInsets.only(right: 4)),
                    Text("${widget.data["className"]}", textAlign: TextAlign.center, style: TextStyle(fontSize: 12, color: MyColor.C7D))
                  ]),
                  Container(height: 8),
                  Row(children: [
                    Expanded(
                        child: Button("上傳教材",
                            isBorderBg: true,
                            bgColor: MyColor.Orange,
                            radius: 4,
                            height: 32,
                            fontSize: 12,
                            margin: EdgeInsets.all(8), onTap: () {
                      PageUtil().openRemoveAll(context, Home(page: 2));
                    })),
                    Expanded(
                        child: Button("預習", bgColor: MyColor.Orange, radius: 4, height: 32, fontSize: 12, margin: EdgeInsets.all(8),
                            onTap: () {
                      PageUtil().open(context, AudioPlayerPage(lessonId: widget.data["lessonId"]));
                    })),
                  ])
                ]))
          ],
        ));
  }
}
